*******************************************************************************
*	This do file analyzes the WHD data to create the tables, figures, and in-text numbers in the paper
*******************************************************************************


*************************************************************************************
*Analyses
use "$whd/working.dta", clear

********************************************************************************
*In-text: 
*Number of cases
count
*Share assessed LDs, by year
tab year_concluded, summ(ld_nonzero)

********************************************************************************
*Figure 1: Share of cases assessed LDs, over time
	graph bar ld_nonzero, ///
		over(tag_rw) over(year_concluded, label(angle(45)))  asyvars ///
		legend(pos(6) cols(2) order(2 "Repeat and/or willful violations" 1 "All other violations")) ///
		ytitle("Share of cases assessed liquidated damages") ysc(r(0 1)) ylabel(0 (0.2) 1)
********************************************************************************
*In-text: 
*Breakdown by repeat/willful
count
tab flsa_repeat_violator
tab flsa_repeat_violator if (flsa_repeat_violator!="R" & flsa_repeat_violator!="RW")
tab flsa_repeat_violator if (flsa_repeat_violator=="R" | flsa_repeat_violator=="RW")

*Breakdown by repeat/willful: MW vs Overtime
tab flsa_repeat_violator if flsa_mw_bw_atp_amt>0 & flsa_ot_bw_atp_amt==0 
tab flsa_repeat_violator if flsa_ot_bw_atp_amt>0 & flsa_mw_bw_atp_amt==0 
tab flsa_repeat_violator if flsa_ot_bw_atp_amt>0 & flsa_mw_bw_atp_amt>0 

*Number which are not asssessed CMP as share of those repeat or willful
count if flsa_cmp_assd_amt==0 & (flsa_repeat_violator=="R" |  flsa_repeat_violator=="W" | flsa_repeat_violator=="RW")
count if  (flsa_repeat_violator=="R" |  flsa_repeat_violator=="W" | flsa_repeat_violator=="RW")

********************************************************************************

*Figure 2: Share of repeat/willful with no CMP, over time
preserve 
	keep if  (flsa_repeat_violator=="R" |  flsa_repeat_violator=="W" | flsa_repeat_violator=="RW")
	gen tag = 1 if flsa_cmp_assd_amt==0
	bysort flsa_repeat_violator year_concluded: egen no_cmp_num = total(tag)
	bysort flsa_repeat_violator year_concluded: egen num = count(flsa_repeat_violator)
	gen no_cmp_share = no_cmp_num/num
	bysort year_concluded: egen all_no_cmp_num = total(tag)
	bysort year_concluded: egen all_num = count(flsa_repeat_violator)
	gen all_no_cmp_share = all_no_cmp_num/all_num
	keep flsa_repeat_violator year_concluded no_cmp_share all_no_cmp_share
	duplicates drop
	sort year_concluded
	twoway (connected all_no_cmp_share year_concluded if year_concluded>2004, lcolor(black) mcolor(black) lwidth(thick)) ///
	(connected no_cmp_share year_concluded if year_concluded>2003 & flsa_repeat_violator=="W", lcolor(navy) mcolor(navy) ) ///
	(connected no_cmp_share year_concluded if year_concluded>2003 & flsa_repeat_violator=="R", lcolor(cranberry) mcolor(cranberry) ) ///
	(connected no_cmp_share year_concluded if year_concluded>2003 & flsa_repeat_violator=="RW", lcolor(dkorange) mcolor(dkorange) ) ///
	 ,graphregion(color(white)) ysc(range(0 0.55)) ylabel(0 (0.1) 0.7) ytitle("Share of repeat/willful violations with no CMP") xtitle("Year concluded") legend(order(1 "All" 2 "First-time, willful" 3 "Repeat, non-willful"  4 "Repeat, willful") pos(6) cols(4))
restore

	*Footnote: number which have CMP but are not repeat or willful
	count if flsa_cmp_assd_amt>0 & (flsa_repeat_violator!="R" & flsa_repeat_violator!="W" & flsa_repeat_violator!="RW")
	
********************************************************************************
*Table 1: 

*Columns "cases" and "Share assessed LD and CMP"
*Full period
bysort flsa_repeat_violator: summ ld_nonzero cmp_nonzero
*2005-2014
bysort flsa_repeat_violator: summ ld_nonzero cmp_nonzero if period==1
*2015-2023
bysort flsa_repeat_violator: summ ld_nonzero cmp_nonzero if period==2

*Columns "p1" through "mean": Civil monetary penalties levied per dollar of back wages (distribution)
*Full period
capture erase "$output/Table1.rtf"
levelsof flsa_repeat_violator, local(flsa_repeat_violator) 
foreach category of local flsa_repeat_violator {
	estpost summarize cmp_per_bw if flsa_repeat_violator=="`category'", d
	esttab using "$output/Table1.rtf", cells("p1(fmt(%9.2f)) p5(fmt(%9.2f)) p10(fmt(%9.2f)) p25(fmt(%9.2f)) p50(fmt(%9.2f)) p75(fmt(%9.2f)) p90(fmt(%9.2f)) p95(fmt(%9.2f)) p99(fmt(%9.2f)) mean(fmt(%9.2f))") append mtitle("`category'")
}
*By sub-period
forvalues i = 1/2 {
capture erase "$output/Table1_p`i'.rtf"
foreach category of local flsa_repeat_violator {
	estpost summarize cmp_per_bw if flsa_repeat_violator=="`category'" & period==`i', d
	esttab using "$output/Table1_p`i'.rtf", cells("p1(fmt(%9.2f)) p5(fmt(%9.2f)) p10(fmt(%9.2f)) p25(fmt(%9.2f)) p50(fmt(%9.2f)) p75(fmt(%9.2f)) p90(fmt(%9.2f)) p95(fmt(%9.2f)) p99(fmt(%9.2f)) mean(fmt(%9.2f))") append mtitle("`category'")
}
}

********************************************************************************
*In-text:

*Share of cases which led to any CMP
summ cmp_nonzero
*Share of cases with a CMP of more than $1 per dollar of back wages
gen cmp_morethan1 = (cmp_per_bw>=1 & !missing(cmp_per_bw))
summ cmp_morethan1

********************************************************************************

*In-text: Hot Goods

*Share of cases with a hot goods violation
gen tag_hotgoods = (_m_hotgoods==3)
summ tag_hotgoods

*Share of hot goods violations in textiles or apparel manufacturing
gen apparel = (naics_3d=="313"|naics_3d=="314"|naics_3d=="315"|naics_3d=="316")
summ apparel if tag_hotgoods==1

*Share of violations in textiles/apparel which featured a hot goods violation
summ tag_hotgoods if apparel==1

*Share of cases by 3-digit NAICS industry which featured a hot goods violation
bysort naics_3d: egen total_violations = count(CASE_ID)
bysort naics_3d: egen share_hotgoods = mean(tag_hotgoods)

*Share of cases in all non-textiles/apparel industries which feature a hot goods violation
preserve
summ apparel //Share of cases which are in textiles/apparel
drop if apparel==1
summ tag_hotgoods //Share of cases not in textiles/apparel which feature a hot goods violation
restore


********************************************************************************

*In-text: Scenario analysis
*

use "$whd/working.dta", clear

keep if period==2

*Expected LD and CMP per dollar of BW for...
*average first-time violator
summ ld_nonzero cmp_per_bw if (flsa_repeat_violator=="N/A"|flsa_repeat_violator=="W")
*average first-time willful violator
summ ld_nonzero cmp_per_bw if (flsa_repeat_violator=="W")
*average repeat violator
summ ld_nonzero cmp_per_bw if flsa_repeat_violator=="R"|flsa_repeat_violator=="RW"
*average repeat willful violator
summ ld_nonzero cmp_per_bw if flsa_repeat_violator=="RW"

*95th percentile CMP per dollar of BW for...
*first-time violator
summ cmp_per_bw if flsa_repeat_violator=="W", d
summ cmp_per_bw if flsa_repeat_violator=="RW", d



